<template>
	<view class="entirety">
		<view class="address">
			<view class="me">
				<text class="defaultl">默认</text>
				<text> {{ pay.recipientName }} {{ pay.phoneNumber }}</text>
			</view>
			<view class="ssq">
				<view class="site">{{ pay.addressLine }}</view>
				<image src="@/static/Myimg/right.png" mode="aspectFit" class="xfj" @click="anniu"></image>
			</view>
		</view>

		<view class="store">
			<view class="dp">
				<image src="../../static/TestImg/img/bizManage.png" mode="aspectFit" class="xfj sjtp"></image>
				<text>{{ pay.name }}</text>
			</view>
			<view class="design">
				<view class="tp">
					<image :src="pay.image[0]" mode="aspectFit" class="stp"></image>
				</view>
				<view class="tu">
					<view class="spms site">{{ pay.productName }}
						<view>
							<view class="fqlm">
								{{ pay.attributes.specs.color }}+{{ pay.attributes.specs.storage }}
							</view>
							<view class="biaoqian">
								<view class="biaoqian-a">
									七天发货
								</view>
							</view>
							<view class="mon">
								<view class="mon-left">
									￥{{ pay.attributes.price }}
								</view>
								<view class="jsqd">
									<u-number-box v-model="value">
										<view slot="minus" class="minus">
											<u-icon name="minus" size="20"></u-icon>
										</view>
										<view slot="input" style="width: 50px;text-align: center;" class="input">
											{{ value }}
										</view>
										<view slot="plus" class="plus">
											<u-icon name="plus" size="20"></u-icon>
										</view>
									</u-number-box>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="fh">
				<view class="psxx">配送信息</view>
				<view class="xsfh">48小时内发货</view>
			</view>
		</view>

		<view class="money">
			<view class="jed">
				<text class="spje">商品金额：</text>
				<text class="qqq">￥{{ pay.attributes.price }}</text>
			</view>
			<view class="jed">
				<text class="spje">运费：</text>
				<text class="qqq">￥0.0</text>
			</view>
			<view class="jed">
				<text>总计：</text>
				<text>￥{{ pay.attributes.price }}</text>
			</view>
		</view>

		<view class="pay">

			<view>
				<image src="../../static/icon/Ring.png" mode="aspectFit" class="nnb"></image>
				牛牛余额支付
			</view>
			<view class="zezz">
				<u-checkbox  shape="circle" label="" size="22" iconSize="20" activeColor="red"
					:checked="true" @change="toggleDefaultAddress"></u-checkbox>
			</view>
		</view>
		<view class="remarks">
			<text class="spje">订单备注</text>
			<input type="text" v-model="detailedAddress" placeholder="和商家协商一致留言" />
		</view>
		<u-button @click="zhifu" text="立即支付" color="#f47"></u-button>


		<u-notify :message="massage" :show="show"></u-notify>
	</view>
</template>

<script>
export default {

	onLoad(e) {
		let userId = uni.getStorageSync("id");

		this.productId = e.productId;

		this.request(`/pay/PayAndOrder?productId=${this.productId}&userId=${userId}`, "get").then((res) => {
			console.log(res);
			this.pay = res.data.result.result
		}).catch((err) => {
			console.log(err);
		})
	},
	// /pay/PayAndOrder/productId=?&userId=?
	data() {
		return {
			checked: false,
			show: false,
			value: 1,
			detailedAddress: null,
			orderNum: "",
			productId: "",
			pay: {},
			show: false,
			massage: ""
		};
	},
	methods: {
		anniu() {
			this.$router.push('/pages/payment/gal');
		},
		open() {
			// console.log('open');
		},
		close() {
			this.show = false
			// console.log('close');
		},
		toggleDefaultAddress(e) {
			this.isDefaultAddress = e.detail.value;
		},
		submitOrder() {
			// 这里实现提交订单的逻辑,通过AJAX发送数据到服务器
			// 添加验证和错误处理
			console.log('Submitting order...');
		},
		zhifu() {
			this.request(`/pay/PayAndOrder?productId=${this.productId}&userId=${uni.getStorageSync("id")}`, "get").then((res) => {
				console.log(res);
				this.pay = res.data.result.result
				this.request(`/pay/createOrder?count=${this.value}&remark=${this.detailedAddress}`, "get").then((res) => {
					this.orderNum = res.data.message;
					this.request(`/pay/payed?count=${this.value}&orderNum=${this.orderNum}`, "get").then((res) => {
						console.log(res);
						if (res.data.code == 200) {
							uni.navigateTo({
								url: "/pages/zhifuchenggong/zhifuchenggong?money=" + res.data.message
							})
						} else {
							this.show = true;
							this.massage = res.data.message;
						}
					})
				}).catch((err) => {
					console.log(err);
				})
			}).catch((err) => {
				console.log(err);
			})

		},

	}
};
</script>


<style scoped>
.entirety {
	width: 100%;
	height: 1200rpx;
	display: flex;
	flex-direction: column;
	justify-content: space-evenly;
	align-items: center;
}

.address {
	width: 100%;
	height: 150rpx;
	display: flex;
	flex-direction: column;
	justify-content: space-evenly;

}

.me {
	margin-left: 35rpx;
}

.defaultl {
	width: 80rpx;
	background-color: #f47;
	color: black;
	text-align: center;
	text-align: center;

}

.ssq {
	display: flex;
	align-items: center;
	justify-content: space-evenly;

}

.xfj {
	width: 35rpx;
	height: 35rpx;
}

.site {
	width: 80%;
	height: 90%;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	font-weight: 600;
	font-size: 33rpx;
}

.store {
	width: 90%;
	height: 450rpx;
	display: flex;
	flex-direction: column;
	justify-content: space-evenly;
	padding: 30rpx;
}

.sjtp {
	border-radius: 50%;
}

.stp {
	width: 100rpx;
	height: 100rpx;
}

.design {
	display: flex;
	justify-content: space-evenly;
	align-content: space-evenly;
}

.tp {
	width: 30%;
	height: 200rpx;
}

.tp image {
	width: 100%;
	height: 100%;
}

.spms {
	width: 100%;
	height: 220rpx;
	font-weight: 400;
	font-size: 32rpx;
	display: flex;
	flex-direction: column;
	align-content: space-evenly;
}

.tu {
	width: 70%;
	height: 200rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	align-content: space-evenly;
}

.fqlm {
	margin-left: 20rpx;
	text-align: left;
	color: #ebebeb;
}

.biaoqian {
	display: flex;
	flex-wrap: wrap;
	margin-left: 20rpx;
}

.biaoqian-a {
	width: auto;
	height: 25rpx;
	border: 2rpx solid black;
	text-align: center;
	padding: 5rpx;
	line-height: 25rpx;
	font-size: 30rpx;
}

.mon {
	width: 100%;
	height: 100rpx;
	display: flex;
	justify-content: space-between;
	margin-left: 20rpx;
}

.mon-left {
	width: 50%;
	height: 100%;
	line-height: 90rpx;
}

.jsqd {
	width: 50%;
	display: flex;
	justify-content: space-evenly;
	align-items: center;
}

.plus,
.minus {
	width: 50rpx;
	height: 50rpx;
	background-color: rgba(0, 0, 0, .1);
	border-radius: 50%;
	text-align: center;
}

.fh {
	display: flex;
	justify-content: space-between;
	font-size: 35rpx;
}

.money {
	width: 98%;
	height: 200rpx;
	display: flex;
	flex-direction: column;
}

.jed {
	width: 100%;
	height: 63rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-size: 42rpx;
}

.nnb {
	width: 35rpx;
	height: 35rpx;
}

.pay,
.remarks {
	width: 98%;
	display: flex;
	justify-content: space-between;
	font-size: 42rpx;
}
</style>